package com.ely.coupon.common.db.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ely.coupon.common.core.utils.BeanConvertUtils;
import com.github.pagehelper.PageInfo;

import java.util.function.Supplier;

public class BeanPageUtils extends BeanConvertUtils {

    /**
     *  PageInfo<ProductCategory> pageInfo
     *  PageInfo<ProductCategoryVo> pageInfoVo
     */

    public static <S, T> PageInfo<T> convertPageInfo(PageInfo<S> source, PageInfo<T> target, Supplier<T> targetSupplier) {
        copyProperties(source, target);
        target.setList(convertListTo(source.getList(), targetSupplier));
        return target;
    }

    /**
     * @param source
     * @param target
     * @param targetSupplier
     * @param <S>
     * @param <T>
     * @return
     */
    public static <S, T> IPage<T> convertPage(IPage<S> source, IPage<T> target, Supplier<T> targetSupplier) {
        copyProperties(source, target);
        target.setRecords(convertListTo(source.getRecords(), targetSupplier));
        return target;
    }
}
